//歌词逻辑
import {watch,onBeforeUpdate,reactive} from 'vue'
import {useStore} from 'vuex'
export function useLyric(list){
  const store=useStore()
  const lyric=reactive({
   //是否显示歌词
   isLyric:false,
   //歌词列表
   lyricList:[],
   getLyricList
  })
  //监视属性
  watch(()=>{store.state.currentTime},function(){
      let p = document.querySelector('p.active')
      if(p){
        let offsetTop = p.offsetTop;
        playLyric.scrollTop = p.offsetTop;
      }
  })

  //切换歌词
  function getLyricList(){
     store.dispatch('reqLyric',{id:store.state.playlist[store.state.playCurrentIndex].id})
  }
  onBeforeUpdate(() => {
    lyric.lyricList=store.getters.lyricList
  })

  return lyric
}